// 20210107 执行该函数获得一个菜单栏
const createNav = (top_div_node, config) => {
    const getNavA = ({text, link}) => {
        let a = document.createElement("a");
        a.innerText = text;
        a.href = link;
        return a;
    };
    const getNavDd = (dd_config) => {
        let elem = document.createElement("dd");
        elem.appendChild(getNavA(dd_config));
        return elem;
    };
    const getNavDl = ({children_nodes}) => {
        let elem = document.createElement("dl");
        elem.className = "layui-nav-child";
        if (children_nodes instanceof Array){
            children_nodes.map((dd_config)=>{
                elem.appendChild(getNavDd(dd_config));
            });
        }
        return elem;
    };
    const getNavLi = (li_config) => {
        let elem = document.createElement("li");
        elem.className = "layui-nav-item";
        elem.appendChild(getNavA(li_config));
        if (li_config.children_nodes && li_config.children_nodes instanceof Array){
            elem.appendChild(getNavDl(li_config));
        }
        return elem;
    };
    const getNavUl = (ul_config) => {
        let elem = document.createElement("ul");
        elem.className = "layui-nav";
        if (ul_config instanceof Array){
            ul_config.map((li_config)=>{elem.appendChild(getNavLi(li_config))})
        }
        return elem;
    };
    top_div_node.appendChild(getNavUl(config));
};

// 导航栏的配置
const nav_config = [
    {
        text: "Louis System Games",
        link: "../test/index.html"
    },
    {
        text: "进程管理",
        link: "#",
        children_nodes: [
            {text: "多级反馈队列", link: "../Process/processScheduling.html"},
            {text: "银行家算法", link: "../banker/banker.html"}
        ]
    },
    {
        text: "磁盘",
        link: "#",
        children_nodes: [
            {text: "磁盘调度策略", link: "../test/canvas01.html"},
        ]
    },
    {
        text: "系统综合展示",
        link: "../VirtualMem/VirtualMem.html"
    },
    {
        text: "Components",
        link: "#",
        children_nodes: [
            {text: "MyConsole", link: "../component/MyConsole.html"},
            {text: "MyStorage", link: "../component/MyStorage.html"},
            {text: "DataCell", link: "../component/DataCell.html"},
            {text: "MyTable", link: "../component/MyTable.html"},
            {text: "JumpingIcon", link: "../component/JumpingIcon.html"},
            {text: "TabCheck", link: "../component/TabCheck.html"},
            {text: "Other", link: "../component/Other.html"},
        ]
    }
];
const top_nav = document.getElementById("top_nav");
createNav(top_nav, nav_config);

// 导航 依赖 element 模块，否则无法进行功能性操作
layui.use('element', function(){
    const element = layui.element;
});